import Vue from 'vue'
import Vuex from 'vuex'
import de from "element-ui/src/locale/lang/de";

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo: JSON.parse(localStorage.getItem('userInfo')),
        token: localStorage.getItem('token')
    },
    getters: {
        getUser: state => {
            return state.userInfo
        },
        getToken: state => {
            return state.token
        }
    },
    mutations: {
        //setters

        //设置token
        SET_TOKEN: (state, token) => {
            state.token = token
            localStorage.setItem('token', token);
        },
        //设置用户信息
        SET_USERINFO: (state, userInfo) => {
            state.userInfo = userInfo
            localStorage.setItem('userInfo', JSON.stringify(userInfo));
        },
        //移除token
        REMOVE_TOKEN: (state) => {
            state.token = ''
            localStorage.removeItem('token')
        },
        //移除用户信息
        REMOVE_INFO: (state) => {
            state.userInfo = {}
            localStorage.removeItem('userInfo')
        }
    },
    actions: {},
    modules: {}
})
